<template>
  <!-- 车主数据》车辆颜色 -->
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <!-- height="auto" -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      :onRowSelectChange="selectChangeHandle"
      columnsRef="potenCus_customer_approval_approval_01"
    >
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="activate">激活</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="approval(1)">批准</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="rejected(1)">驳回</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="distribution(1)">分配</el-button>-->
        <multiuse-button
          size="small"
          type="primary"
          :click="activate"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueActive"
        >激活</multiuse-button>
        <multiuse-button
          size="small"
          type="primary"
          :click="approval.bind(this, 1)"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueAudit"
        >批准</multiuse-button>
        <multiuse-button
          size="small"
          type="primary"
          :click="rejected.bind(this, 1)"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueAudit"
        >驳回</multiuse-button>
        <multiuse-button
          size="small"
          type="primary"
          :click="distribution.bind(this, 1)"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueAudit"
        >分配</multiuse-button>
      </template>
    </FilterTable>
    <Drawer
      :visible.sync="visible"
      :title="dialogTitle"
      :width="1100"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <detail :type="handleType" :rowData="formData" @close="closeHandler" />

      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'center'
        }"
      >
        <!-- <el-button v-if="formData.isAudited == '1'" size="small" type="primary" @click="activate">激活</el-button> -->
        <multiuse-button
          v-if="formData.isAudited == '1'"
          size="small"
          type="primary"
          :click="activate"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueActive"
        >激活</multiuse-button>
        <el-button @click="visible = false">返 回</el-button>
        <!-- <el-button v-if="formData.isAudited != '1'" size="small" type="primary" @click="approval(0, formData)">批准</el-button>
        <el-button v-if="formData.isAudited != '1'" size="small" type="primary" @click="rejected(0, formData)">驳回</el-button>
        <el-button v-if="formData.isAudited != '1'" size="small" type="primary" @click="distribution(0, formData)">分配</el-button>-->
        <multiuse-button
          v-if="formData.isAudited != '1'"
          size="small"
          type="primary"
          :click="approval.bind(this, 0, formData)"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueAudit"
        >批准</multiuse-button>
        <multiuse-button
          v-if="formData.isAudited != '1'"
          size="small"
          type="primary"
          :click="rejected.bind(this, 0, formData)"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueAudit"
        >驳回</multiuse-button>
        <multiuse-button
          v-if="formData.isAudited != '1'"
          size="small"
          type="primary"
          :click="distribution.bind(this, 0, formData)"
          :auth-list="auths"
          auth-mark="/api/cyxdms.clue/clueaudit/clueAudit"
        >分配</multiuse-button>
      </div>
    </Drawer>

    <el-dialog
      :visible.sync="rejectedVisible"
      title="驳回意见"
      :type="rejectedHandleType"
      :rowData="rejectedFormData"
      width="30%"
    >
      <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="textarea"></el-input>
      <div :style="{
          marginTop:'10px',
          textAlign: 'right'
        }">
        <el-button @click="closeVisible">取 消</el-button>
        <el-button type="primary" :loading="saveLoading" @click="rejectedHandler">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="consultVisible"
      title="选择顾问"
      :type="consultHandleType"
      :rowData="consultFormData"
      width="80%"
    >
      <el-radio-group v-model="radio">
        <el-radio
          v-for="(item, index) in consults"
          :key="index"
          style="width:160px"
          :label="item.value"
        >{{ item.text }}</el-radio>
      </el-radio-group>
      <div :style="{
            marginTop:'10px',
            textAlign: 'right'
          }">
        <el-button @click="consultcloseVisible">取 消</el-button>
        <el-button type="primary" :loading="saveLoading" @click="consultHandler">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getApprovalList, getAllModal, getAllClueSource, clueActive, clueAudit, queryClueSourceList } from '@/api/potenCus/customer/approval';
import { dictionary } from '@/utils/dictMixin';
import approvalModal from './approvalModal';
import detail from '../potenCusManage/detail';
import { getCategories, getPartitionById } from '@/api/potenCus/basedata/cluesPrameter';
import { formatDates } from '@/utils/validate';
import { authority } from '@/utils/authMixin';
import { addDate } from '@/utils/index';
import { getAllHeatUp } from '@/api/potenCus/basedata/clueFever';
export default {
  name: 'approval',
  mixins: [dictionary, authority],
  components: {
    approvalModal,
    detail
  },
  props: {
    dataType: {
      type: String,
      default: 'clue'
    }
  },
  data() {
    return {
      topFilterList: this.createTopFilters(),
      fetchParams: { dataType: this.dataType, isAudited: '0' },
      selectedRows: [], //选中列表中的行
      visible: false,
      rejectedVisible: false,
      consult: -1, // 0:激活，1:分配
      consultVisible: false,
      dialogTitle: '',
      fetchApi: getApprovalList,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      rejectedHandleType: '',
      rejectedFormData: {},
      consultHandleType: '',
      consultFormData: {},
      conf: { add: '新增', edit: '编辑', show: '显示' },
      textarea: '',
      radio: '',
      consults: [],
      temperatureList: [],
      saveLoading: false
    };
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '关键字',
          fieldName: 'combineStr',
          placeholder: '客户名称/手机号'
        },
        {
          type: 'RANGE_DATE',
          label: '申请时间',
          fieldName: 'time',
          placeholder: '请输入',
          dateType: 'exactdaterange'
        },
        {
          type: 'SELECT',
          label: '审批状态',
          fieldName: 'isAudited',
          placeholder: '请选择',
          initialValue: '0',
          itemList: [
            { text: '已审批', value: '1' },
            { text: '未审批', value: '0' }
          ]
        },
        {
          type: 'INPUT_TREE',
          label: '线索来源',
          fieldName: 'clueSourceIds',
          placeholder: '请选择',
          itemList: []
        },
        /*{
          type: 'SELECT',
          label: '来源大类',
          fieldName: 'clueSourceBig',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeCategoriesSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '来源细分',
          fieldName: 'clueSourceDetail',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeMince(val);
          }
        },*/
        {
          type: 'SELECT',
          label: '订金类型',
          fieldName: 'depositType',
          placeholder: '请选择',
          itemList: this.createDictList('8050')
        },
        {
          type: 'INPUT_CASCADER',
          label: '意向车型',
          fieldName: 'carType',
          placeholder: '请选择',
          options: { titles: ['品牌', '车系', '车型'] },
          itemList: []
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-popover placement="bottom" width="200" trigger="click" disabled={props.row.isAudited == '1'}>
                  <multiuse-button type="primary" click={() => this.approval(0, props.row)} auth-list={this.auths} auth-mark={'/api/cyxdms.clue/clueaudit/clueAudit'}>
                    批准
                  </multiuse-button>
                  <multiuse-button type="primary" click={() => this.rejected(0, props.row)} auth-list={this.auths} auth-mark={'/api/cyxdms.clue/clueaudit/clueAudit'}>
                    驳回
                  </multiuse-button>
                  <multiuse-button type="primary" click={() => this.distribution(0, props.row)} auth-list={this.auths} auth-mark={'/api/cyxdms.clue/clueaudit/clueAudit'}>
                    分配
                  </multiuse-button>
                  <el-button
                    slot="reference"
                    v-show={this.authMark('/api/cyxdms.clue/clueaudit/clueAudit')}
                    disabled={props.row.isAudited == '1'}
                    size="mini"
                    type="text"
                    onClick={() => this.examination(props.row)}
                  >
                    审批
                    <el-divider direction="vertical" />
                  </el-button>
                </el-popover>
                <el-button size="mini" type="text" onClick={() => this.showHandle(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'potentialCustomerNo',
          width: 130,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: props => {
            return <span>{this.createDictText(props.row.customerType, '1523')}</span>;
          }
        },
        {
          title: '订金类型',
          dataIndex: 'depositType',
          align: 'center',
          filterType: 'checkbox',
          filterItems: this.createDictList('8050'),
          render: props => {
            return <span>{this.createDictText(props.row.depositType, '8050')}</span>;
          }
        },
        {
          title: '订金金额',
          dataIndex: 'depositAmount',
          sorter: true,
          filter: true,
          width: 150,
          align: 'center',
          filterType: 'input'
        },
        {
          title: '联系人姓名',
          dataIndex: 'contactName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'gender',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1002'),
          render: props => {
            return <span>{this.createDictText(props.row.gender, '1002')}</span>;
          }
        },
        {
          title: '手机号码',
          dataIndex: 'mobilePhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '线索类型',
          dataIndex: 'clueType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7019'),
          render: props => {
            return <span>{this.createDictText(props.row.clueType, '7019')}</span>;
          }
        },
        {
          title: '线索来源',
          dataIndex: 'clueSourceNameBig',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        /*{
          title: '来源大类',
          dataIndex: 'clueSourceNameBig',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '来源细分',
          dataIndex: 'clueSourceNameSmall',
          sorter: true,
          filter: true,
          filterType: 'input'
        },*/
        {
          title: '意向品牌',
          dataIndex: 'inteBrandName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向车系',
          dataIndex: 'inteCarSeriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向车型',
          dataIndex: 'inteCarTypeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向配置',
          dataIndex: 'inteYearStyleName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向选装',
          dataIndex: 'intentOptionName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向颜色（外饰）',
          dataIndex: 'inteColourName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向颜色（内饰）',
          dataIndex: 'interiorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '意向内饰色',// 意向内饰色没有
        //   dataIndex: 'inteColourName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '线索热度',
          dataIndex: 'temperature',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          render: props => {
            return <span>{this.hotDictText(props.row.temperature)}</span>;
          }
          // filterItems: this.createDictList('7018'),
          // render: props => {
          //   return <span>{this.createDictText(props.row.temperature, '7018')}</span>;
          // }
        },
        {
          title: '意向级别（初始）',
          dataIndex: 'initailLevel',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1519'),
          render: props => {
            return <span>{this.createDictText(props.row.initailLevel, '1519')}</span>;
          }
        },
        {
          title: '创建人',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建时间',
          width: 150,
          dataIndex: 'createdAt',
          sorter: true,
          // filter: true,
          // filterType: 'date-range',
          // dateFormat: 'yyyy-MM-dd HH:mm:ss',
          render: props => {
            return <span>{formatDates(props.row.createdAt)} </span>;
          }
        },
        {
          title: '是否下发',
          dataIndex: 'isDown',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isDown, '1004')}</span>;
          }
        },
        {
          title: '下发时间',
          width: 150,
          dataIndex: 'issuedDate',
          sorter: true,
          // filter: true,
          // filterType: 'date-range',
          // dateFormat: 'yyyy-MM-dd HH:mm:ss',
          render: props => {
            return <span>{formatDates(props.row.issuedDate)} </span>;
          }
        },
        {
          title: '是否进店',
          dataIndex: 'isArrived',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isArrived, '1004')}</span>;
          }
        },
        {
          title: '进店类型',
          dataIndex: 'passengerFlowType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7003'),
          render: props => {
            return <span>{this.createDictText(props.row.passengerFlowType, '7003')}</span>;
          }
        },
        {
          title: '是否试驾',
          dataIndex: 'isTestDrive',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isTestDrive, '1004')}</span>;
          }
        },
        {
          title: '申请人',
          dataIndex: 'applyPerson',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '申请时间',
          width: 150,
          dataIndex: 'applyDate',
          sorter: true,
          // filter: true,
          // filterType: 'date-range',
          // dateFormat: 'yyyy-MM-dd HH:mm:ss',
          render: props => {
            return <span>{formatDates(props.row.applyDate)} </span>;
          }
        },
        {
          title: '申请原因',
          dataIndex: 'resultReason',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '跟进情形',
          dataIndex: 'scene',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '审批状态',
          dataIndex: 'isAudited',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '已审批', value: '1' },
            { text: '未审批', value: '0' }
          ],
          render: props => {
            return <span>{props.row.isAudited == '1' ? '已审批' : '未审批'}</span>;
          }
        },
        {
          title: '审批结果',
          dataIndex: 'auditStatus',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    showHandle(row) {
      this.handleType = 'show';
      row = {
        ...row,
        customerBusinessId: row.id,
        clueType: 70241002 // 后台确定写死
        // clueType: row.dataType === 'clue' ? 70241001:70241002
      };
      this.formData = row;
      let arr = [];
      arr.push(row);
      this.selectedRows = arr;
      this.showHandler();
    },
    examination(row) {
      if (row.isAudited == '1') {
        return;
      }
      if (row.id) {
        console.log('审批', row);
      } else if (this.selectedRows.length > 0) {
        console.log('审批', this.selectedRows);
      } else {
        this.$message.info('请先选择线索！');
      }
    },
    async activate() {
      this.saveLoading = false;
      let self = this;
      if (this.selectedRows.length > 0) {
        let a = 1;
        this.selectedRows.map(x => {
          if (x.isAudited == '0') {
            a = 0;
          } else if (x.isAudited == '1' && x.auditStatus !== '批准') {
            a = 0;
          }
        });
        if (a === 0) {
          this.$message.info('线索未批准无效/战败，不需要激活');
          return;
        }
        console.log('激活', this.selectedRows);
        this.consult = 0;
        this.consultVisible = true;
      } else {
        this.$message.info('请先选择线索！');
      }
    },
    // 批准
    approval(index, row) {
      this.saveLoading = false;
      let self = this;
      if (index === 0) {
        console.log('批准', row);
        if (row.isAudited == '1') {
          this.$message.info('已审批线索不可“审批/驳回/分配”');
        } else {
          this.approvalChange('0', row);
        }
      } else if (this.selectedRows.length > 0) {
        console.log('批准', this.selectedRows);
        let isAudited = 0;
        for (let i = 0; i < self.selectedRows.length; i++) {
          if (self.selectedRows[i].isAudited == '1') {
            self.$message.info('已审批线索不可“审批/驳回/分配”');
            isAudited = 1;
            break;
          }
        }
        if (isAudited == 0) {
          this.approvalChange('0');
        }
      } else {
        this.$message.info('请先选择线索！');
      }
    },
    // 驳回
    rejected(index, row) {
      this.saveLoading = false;
      let self = this;
      if (index === 0) {
        console.log('驳回', row);
        if (row.isAudited == '1') {
          this.$message.info('已审批线索不可“审批/驳回/分配”');
        } else {
          this.row = row;
          this.rejectedVisible = true;
        }
        // this.approvalChange('1', row)
      } else if (this.selectedRows.length > 0) {
        console.log('驳回', this.selectedRows);
        let isAudited = 0;
        for (let i = 0; i < self.selectedRows.length; i++) {
          if (self.selectedRows[i].isAudited == '1') {
            self.$message.info('已审批线索不可“审批/驳回/分配”');
            isAudited = 1;
            break;
          }
        }
        if (isAudited == 0) {
          this.rejectedVisible = true;
        }
        // this.approvalChange('1')
      } else {
        this.$message.info('请先选择线索！');
      }
      // this.rejectedVisible = true;
    },
    // 分配
    distribution(index, row) {
      this.saveLoading = false;
      let self = this;
      if (index === 0) {
        if (row.isAudited == '1') {
          this.$message.info('已审批线索不可“审批/驳回/分配”');
        } else {
          this.row = row;
          this.consult = 1;
          this.consultVisible = true;
        }
      } else if (this.selectedRows.length > 0) {
        let isAudited = 0;
        for (let i = 0; i < self.selectedRows.length; i++) {
          if (self.selectedRows[i].isAudited == '1') {
            self.$message.info('已审批线索不可“审批/驳回/分配”');
            isAudited = 1;
            break;
          }
        }
        if (isAudited == 0) {
          this.consult = 1;
          this.consultVisible = true;
        }
      } else {
        this.$message.info('请先选择线索！');
      }
    },
    // 审批修改
    async approvalChange(auditStatus, row) {
      let data = {
        auditType: this.dataType == 'clue' ? 0 : 1, // 审批类型: 0:无效线索 1:战败审批
        clueAuditDetails: [], // 审批对象列表
        consults: this.radio
      };
      console.log(row);
      if (row) {
        data.clueAuditDetails.push({
          actionId: row.actionId, // 最近的actonId
          auditStatus: auditStatus, // 审批结果:0-批准;1-驳回;2-再分配
          clueId: row.id, // 线索ID
          dataType: row.dataType, // 数据类型: clue-线索;biz-商机
          remark: auditStatus == 1 ? this.textarea : row.remark // 备注
        });
      } else {
        this.selectedRows.map((x, i) => {
          data.clueAuditDetails.push({
            actionId: x.actionId, // 最近的actonId
            auditStatus: auditStatus, // 审批结果:0-批准;1-驳回;2-再分配
            clueId: x.id, // 线索ID
            dataType: x.dataType, // 数据类型: clue-线索;biz-商机
            remark: auditStatus == 1 ? this.textarea : x.remark // 备注
          });
        });
      }
      console.log(data);
      const res = await clueAudit(data);
      if (res.resultCode === 200) {
        this.rows = '';
        this.selectedRows = [];
        if (auditStatus == 1 || auditStatus == 2) {
          this.closeVisible();
          this.consultcloseVisible();
        }
        console.log(auditStatus);
        if (auditStatus == 0) {
          this.$message.success('批准成功!');
        } else if (auditStatus == 1) {
          this.$message.success('驳回成功!');
        } else if (auditStatus == 2) {
          this.$message.success('分配成功!');
        } else {
          this.saveLoading = false;
        }
        this.closeHandler(false, 'refresh');
        //this.saveLoading = false;
        // console.log(res.data)
      }
    },
    // 激活修改
    async activateChange() {
      let data = {
        clueActiveDetailList: [],
        consultants: this.radio
      };
      this.selectedRows.map(x => {
        data.clueActiveDetailList.push({
          activeType: this.dataType == 'clue' ? 0 : 1, // 激活类型 0:无效激活 1:战败激活
          id: x.id,
          mobilePhone: x.mobilePhone
        });
      });

      const res = await clueActive(data);
      if (res.resultCode === 200) {
        this.$message.success('激活成功!');
        this.selectedRows = [];
        this.consultcloseVisible();
        this.closeHandler(false, 'refresh');
        // console.log(res.data)
      } else {
        this.saveLoading = false;
      }
    },
    rejectedHandler() {
      this.saveLoading = true;
      console.log(this.row);
      if (this.row) {
        this.approvalChange('1', this.row);
      } else {
        this.approvalChange('1');
      }
      // this.closeVisible()
    },
    closeVisible() {
      this.textarea = '';
      this.rejectedVisible = false;
    },
    consultHandler() {
      this.saveLoading = true;
      if (this.consult === 0) {
        this.activateChange();
      } else if (this.radio) {
        if (this.row) {
          this.approvalChange('2', this.row);
        } else {
          this.approvalChange('2');
        }
      } else {
        this.saveLoading = false;
        this.$message.info('请先选择顾问');
      }
      //this.saveLoading = false;
      // this.consultcloseVisible()
    },
    consultcloseVisible() {
      this.radio = '';
      this.consultVisible = false;
    },
    selectChangeHandle(rows) {
      // if (!rows.length) return;
      this.selectedRows = rows;
    },
    showHandler() {
      this.dialogTitle = `明细`;
      this.visible = true;
    },
    changeHandle(val) {
      if (val.time) {
        val.applyDateStart = val.time[0];
        val.applyDateEnd = val.time[1];
      } else {
        val.applyDateStart = '';
        val.applyDateEnd = '';
      }
      // console.log(val)
      if (val.carType) {
        val.inteBrand = val.carType.split(',')[0];
        val.inteCarSeries = val.carType.split(',')[1];
        if (val.carType.split(',')[2] != 0) {
          val.inteCarType = val.carType.split(',')[2];
        }
      } else {
        val.inteBrand = undefined;
        val.inteCarSeries = undefined;
        val.inteCarType = undefined;
      }
      if (this.dataType) {
        this.fetchParams = Object.assign({ dataType: this.dataType }, val);
      } else {
        this.fetchParams = Object.assign({}, val);
      }
      // console.log(this.fetchParams)
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    // 车型
    async getModalList() {
      const res = await getAllModal({ type: 0, level: 3, isUnlimited: 10041001 });
      // console.log('车型信息', res)
      if (res.resultCode === 200) {
        this.topFilterList.find(item => item.fieldName === 'carType').itemList = res.data;
      }
    },
    // // 客档来源
    // async getAllClueSource() {
    //   const res = await getAllClueSource({dataType: 70261002 ,level: 2});
    //   // console.log('车型信息', res)
    //   if (res.resultCode === 200) {
    //     this.topFilterList[3].itemList = res.data.map(x => ({ value: x.id, text: x.clueName }));
    //   }
    // },
    // 客档来源
    async getClueTree() {
      const res = await queryClueSourceList();
      console.log('客档来源', res);
      if (res.resultCode === 200) {
        let treeList = res.data;
        treeList.forEach(el => {
          el.text = el.clueName;
          el.value = el.id;
          el.parentId = el.parentId;
        });

        this.topFilterList.find(item => item.fieldName === 'clueSourceIds').itemList = treeList;
      }
    },
    async getCateList() {
      const res = await getCategories();
      // console.log('来源大类', res)
      if (res.resultCode === 200) {
        this.topFilterList[3].itemList = res.data.map(x => ({ value: x.id, text: x.clueName }));
      }
    },
    async changeCategoriesSelect(id) {
      if (!id) {
        this.topFilterList[4].initialValue = '';
        this.topFilterList[4].itemList = [];
      } else {
        const res = await getPartitionById(id);
        // console.log('来源细分', res)
        if (res.resultCode === 200) {
          this.topFilterList[4].itemList = res.data.map(x => ({ value: x.id, text: x.clueName }));
        }
        if (this.topFilterList[4].initialValue) {
          this.topFilterList[4].initialValue = '';
        }
      }
    },
    changeMince(val) {
      if (!this.topFilterList[3].initialValue) {
        this.topFilterList[4].initialValue = '';
        this.topFilterList[4].itemList = [];
        this.$message.info('请先选择来源大类');
      }
    },
    // 获取所有线索热度级别定义
    async getAllHeatUp() {
      const res = await getAllHeatUp({ isValid: 10041001 });
      // console.log('客档来源', res)
      if (res.resultCode === 200) {
        let hotList = [];
        res.data.forEach(el => {
          hotList.push({
            text: el.clueHeatName,
            value: el.id
          });
        });
        this.columns.find(item => item.dataIndex === 'temperature').filterItems = hotList;
        this.temperatureList = hotList;
      }
    },
    // val -> 数据的值
    hotDictText(val) {
      let res = '';
      if (!val) return res;
      if (this.temperatureList) {
        const target = this.temperatureList.find(x => x.value == val);
        res = target ? target.text || '' : val;
      }
      return res;
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    //this.saveLoading = false;
  },
  created() {
    this.getModalList();
    this.getClueTree();
    this.getAllHeatUp();
    //this.saveLoading = false;
    // this.getCateList()
    let roleType = this.dataType === 'clue' ? '10061012' : '10061012,10061015';
    this.getConsultant(1, roleType).then(result => {
      this.consults = result;
    });
  }
};
</script>

<style lang="less" scoped>
</style>
